using System;
using UnityEngine;

namespace utils
{
    [ExecuteInEditMode]
    public class AutoRotate : MonoBehaviour
    {
        private float minAngle = 0;
        private float maxAngle = 180;
        private float lastFloor = 0;
        void Update()
        {
            var time = Time.time / 10;
            // transform.RotateAround(Vector3.zero, Vector3.up, 10 * Time.deltaTime);
            if (Math.Abs(Mathf.Floor(time) - lastFloor) > 0.001){
                (minAngle, maxAngle) = (maxAngle, minAngle);
                lastFloor = Mathf.Floor(time);
            }
            var angle = Mathf.LerpAngle(minAngle, maxAngle, time - Mathf.Floor(time));
            transform.eulerAngles = new Vector3(10, angle, 0);
        }
    }
}
